local mozhan = fk.CreateSkill {
    name = "cao__mozhan",
}

Fk:loadTranslationTable {
    ["cao__mozhan"] = "墨战",
    [":cao__mozhan"] = "摸牌阶段，你可以多摸两张牌，然后将手牌中一种颜色的牌当作一张【万箭齐发】使用。",

    ["#cao__mozhan__choose"] = "墨战：选择一种颜色的手牌当【万箭齐发】使用。",
    ["mz_red"] = "红色",
    ["mz_black"] = "黑色"
}

mozhan:addEffect(fk.DrawNCards, {
    anim_type = "drawcard",
    on_use = function(self, event, target, player, data)
        data.n = data.n + 2
        player:setMark("@zk__mozhan", 1)
    end,
})

mozhan:addEffect(fk.EventPhaseEnd, {
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(mozhan.name) and player:getMark("@zk__mozhan") == 1
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        player:setMark("@zk__mozhan", 0)
        local cards = player:getCardIds("h")
        if #cards ~= 0 then
            local reds = {}
            local blacks = {}
            for _, i in ipairs(cards) do
                local card = Fk:getCardById(i)
                if card.color == Card.Red then table.insert(reds, i)
                else table.insert(blacks, i) end
            end
            local all_choices = {}
            if #reds ~= 0 then table.insert(all_choices, "mz_red") end
            if #blacks ~= 0 then table.insert(all_choices, "mz_black") end
            local choice = room:askToChoice(player, {
                choices = {"mz_red", "mz_black"},
                skill_name = mozhan.name,
                cancelable = false,
                prompt = "#zk__mozhan__choose"
            })
            if choice == "mz_red" then room:useVirtualCard("archery_attack", reds, player, room:getOtherPlayers(player, false), mozhan.name) end
            if choice == "mz_black" then room:useVirtualCard("archery_attack", blacks, player, room:getOtherPlayers(player, false), mozhan.name) end
        end
    end
})

return mozhan